package com.coderxq.blog.web.contoller;

import com.coderxq.blog.utils.ResponseResult;
import com.coderxq.blog.web.entity.dto.RoleMenuList;
import com.coderxq.blog.web.entity.pojo.Role;
import com.coderxq.blog.web.entity.pojo.RoleMenu;
import com.coderxq.blog.web.entity.vo.RoleInfoVo;
import com.coderxq.blog.web.service.role.RoleService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * @Author: lijingming
 * @Date: 2025/2/15
 * @Description:
 **/
@RestController
@RequestMapping("/Role")
@Api(tags = "角色管理")
public class RoleApi {
    private static final Logger logger = LoggerFactory.getLogger(RoleApi.class);


    @Autowired
    private RoleService roleService;


    @PostMapping("/insertRole")
    public int insertRole(@RequestBody Role role) {
        logger.info("RoleApi.insertRole()");
        return roleService.insertRole(role);
    }



    @PostMapping("/deleteRole")
    public int deleteRole(String roleId) {
        logger.info("RoleApi.deleteRole()");
        return roleService.deleteRole(roleId);
    }

    @PostMapping("/updateRole")
    public Role updateRole(String roleId, String roleName) {
        logger.info("RoleApi.updateRole()");
        return roleService.updateRole(roleId, roleName);
    }

    @GetMapping("/findAllRoleList")
    public ResponseResult findAllRoleList(@RequestParam int pageNum, @RequestParam int pageSize) {
        logger.info("RoleApi.findAllRoleList()");
        PageInfo<Role> roleList=roleService.findAllRoleList(pageNum,pageSize);

        return ResponseResult.okData(roleList);
    }



    @GetMapping("/findRoleById")
    public Role findRoleById(String roleId) {
        logger.info("RoleApi.findRoleById()");
        return roleService.findRoleById(roleId);
    }

    @PostMapping("/insertRoleMenu")
    public ResponseResult insertRoleMenu(@RequestBody RoleMenu roleMenu) {
        logger.info("RoleApi.insertRoleMenu()");
        int result = roleService.insertRoleMenu(roleMenu);
        return ResponseResult.okData(result);
    }

    //重置角色所有菜单
    @PostMapping("/resetRoleMenuList")
    public ResponseResult resetRoleMenuList(@RequestBody RoleMenuList roleMenuList) {
        logger.info("RoleApi.insertRoleMenu()");
        int result = roleService.resetRoleMenuList(roleMenuList);
        return ResponseResult.okData(result);
    }

    @PostMapping("/deleteRoleMenu")
    public int deleteRoleMenu( String roleId,  String menuId) {
        logger.info("RoleApi.deleteRoleMenu()");
        return roleService.deleteRoleMenu(roleId, menuId);
    }

    @GetMapping("/findRoleMenuList")
    public ResponseResult findRoleMenuList(@RequestParam String roleId) {
        logger.info("RoleApi.findRoleMenuList()");
        RoleInfoVo roleInfo = roleService.findRoleMenuList(roleId);
        return ResponseResult.okData(roleInfo);
    }
}
